package com.lxq.LeetCode.getIntersectionNode;

import com.lxq.DataStructure.ListNode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;

public class Solution {
    public static void main(String[] args) {

    }

    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode res = null;
        HashSet<ListNode> hs = new HashSet<ListNode>();
        while (headA != null) {
            hs.add(headA);
            headA = headA.next;
        }
        while ((!hs.contains(headB)) && headB != null) {
            headB = headB.next;
        }
        res = headB;
        return res;
    }
}
